package com.huawei.hotel.controller;

import com.huawei.hotel.common.utils.Page;
import com.huawei.hotel.service.StudentService;
import com.huawei.hotel.vo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 18902
 * @date 2020/10/25 13:15
 */
@Controller
public class StudentController {
    //依赖注入
    @Autowired(required = true)
    private StudentService studentService;

    /**
     * 根据姓名或者学号查询学生列表
     */
    @RequestMapping(value = "/student/list")
    public String list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer rows,
                       @RequestParam("stu_name") String stu_name, @RequestParam("stu_acount") String stu_acount, Model model) {
        System.out.println(stu_name);
        System.out.println(stu_acount);
        //根据条件查询所有的学生
        Page<Student> students = studentService.findStudentList(page, rows, stu_name, stu_acount);
        model.addAttribute("page", students);
        model.addAttribute("stu_name", stu_name);
        model.addAttribute("stu_acount", stu_acount);
        return "student_list";
    }

    /**
     * 查询所有学生列表
     */
    @RequestMapping(value = "/student/allList")
    public String allList(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer rows,
                          Model model) {
        String stu_name = null;
        String stu_acount = null;
        //根据条件查询所有的学生
        Page<Student> students = studentService.findStudentList(page, rows, stu_name, stu_acount);
        model.addAttribute("page", students);
        return "student_list";
    }
}
